package com.sgcc.fj.pmos.mobileapp.adapter;

import android.text.TextUtils;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.fj.pmos.mobileapp.bean.LinkmanInfoBean;

public class ContactPersonInfoAdapter extends BaseQuickAdapter<LinkmanInfoBean.DataBean, BaseViewHolder> {

    public ContactPersonInfoAdapter() {
        super(R.layout.item_contactpersoninfo);
    }

    public interface BtnClickListener {
        void delete(int position, LinkmanInfoBean.DataBean bean);

        void edit(int position, LinkmanInfoBean.DataBean bean);
    }

    public void setBtnClickListener(BtnClickListener btnClickListener) {
        mBtnClickListener = btnClickListener;
    }

    private BtnClickListener mBtnClickListener;

    @Override
    protected void convert(BaseViewHolder baseViewHolder, LinkmanInfoBean.DataBean bean) {
        String s = bean.getIsCommomContact().equals("1") ? bean.getContactName() + "(" + bean.getDoucumentNumber() + ")" : bean.getContactName();
        baseViewHolder.setText(R.id.tv_contactName, s);
        baseViewHolder.setVisible(R.id.tvIsFirstContact, bean.getIsCommomContact().equals("1"));
        baseViewHolder.setText(R.id.tv_telephone, bean.getTelephone());
        baseViewHolder.setText(R.id.tv_contactType, getTextStr(bean.getContactType()));
        baseViewHolder.setText(R.id.tv_officePhone, bean.getOfficePhone());
        baseViewHolder.setText(R.id.tv_email, bean.getEmail());
        baseViewHolder.setText(R.id.tv_remarks, bean.getRemarks());
        baseViewHolder.getView(R.id.rl_delete).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mBtnClickListener != null) {
                    mBtnClickListener.delete(getItemPosition(bean), bean);
                }
            }
        });
        baseViewHolder.getView(R.id.rl_edit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mBtnClickListener != null) {
                    mBtnClickListener.edit(getItemPosition(bean), bean);
                }
            }
        });
    }

    private String getTextStr(String contactType) {
        if (TextUtils.isEmpty(contactType))
            return "";
        StringBuffer sb = new StringBuffer();
        String contactTypes[] = contactType.split(",");
        for (int i = 0; i < contactTypes.length; i++) {
            if ("1".equals(contactTypes[i])) {
                sb.append("注册,");
            }
            if ("2".equals(contactTypes[i])) {
                sb.append("交易,");
            }
            if ("5".equals(contactTypes[i])) {
                sb.append("结算,");
            }
            if ("6".equals(contactTypes[i])) {
                sb.append("合规,");
            }
        }
        return sb.toString().substring(0, sb.toString().length() - 1);
    }
}
